package com.skp.shaphan.ui.buttons;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

import com.skp.shaphan.actions.CompareTablesAction;
import com.skp.shaphan.ui.windows.CompareOutputWindow;
import com.skp.shaphan.ui.windows.CompareTablesWindow;

public class CompareTablesOkButton extends JButton implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1797394610363896506L;
	private CompareTablesWindow window;

	public CompareTablesOkButton(CompareTablesWindow window) {
		super("OK");
		this.window = window;
		setMnemonic('O');
		addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		CompareOutputWindow outputWindow = new CompareOutputWindow((JFrame) window.getOwner());
		
		CompareTablesAction action = new CompareTablesAction();
		action.setLeftConnId(window.getLeftConnId());
		action.setRightConnId(window.getRightConnId());
		action.setTables(window.getRecords());
		action.setOutput(outputWindow);
		action.setOutputPath(window.getOutputPath());
		window.dispose();
		
		outputWindow.setVisible(true);
		
		Thread t = new Thread(action);
		t.start();
	}
}
